'use strict';
const path = require('path');
module.exports = appInfo => {
  const config = {};
  config.key = appInfo.name;
  config.frameDebug = false;
  // 中间件，应用新创建需在这里配置
  config.middleware = [ ];
  // 权限模块配置，该配置如果关闭，auth/webAuth/jwt都将无效
  config.permission = {
    enable: true,
  };

  // client=web时的校验中间件配置参数
  config.webAuth = {
    interfaceEnable: false, // 是否开启接口校验
    interfaceAccess: [], // 接口白名单
  };
  // web安全配置，详见：https://eggjs.org/zh-cn/core/security.html
  config.security = {
    csrf: { enable: false },
    domainWhiteList: [ 'http://localhost:9527' ],
  };
  // 七牛图片上传配置
  config.qiniu = {
    enable: false,
    accessKey: '七牛accessKey',
    secretKey: '七牛secretKey',
    bucket: '七牛bucket',
    host: '七牛cdn域名',
    uploadUrl: '七牛上传域名',
  };
  // redis配置
  config.redis = {
    client: {
      port: 6379, // 端口
      host: '127.0.0.1', // host
      password: '',
      db: 0,
    },
  };
  // mongoose数据库配置
  config.mongoose = {
    url: 'mongodb://127.0.0.1:27017/' + appInfo.name,
    options: {
      reconnectTries: Number.MAX_VALUE,
      reconnectInterval: 1000,
      socketTimeoutMS: 1000 * 60 * 60, // 1小时超时
      useCreateIndex: true,
      useUnifiedTopology: true,
      useFindAndModify: false,
      bufferCommands: false,
    },
  };
  // 项目启动配置
  config.cluster = {
    listen: {
      port: 7001,
      hostname: '127.0.0.1',
    },
  };

  // 静态资源目录
  config.static = {
    prefix: '/',
    dir: path.join(appInfo.baseDir, 'public'),
    buffer: false,
  };

  // 路由中间件
  config.groupRouter = {
    weapp: { middleware: [ 'weappAuth' ] },
  };

  return { ...config };
};
